<!--
菜单管理页
凌辉
2017-4-12
-->
<template>
  <div>
    <el-col :span="24" style="padding-bottom: 0px;" v-show="listShow">
      <el-col :span="24" style="padding-bottom: 0px;height:46px">
        <el-form :inline="true">
          <el-form-item>
            <el-select v-model="accountQuery" size="small" id="el-select" style="vertical-align:top;">
              <el-option label="菜单类型" value=""/>
              <el-option label="运营" value="0"/>
              <el-option label="商家" value="1"/>
              <el-option label="代理商" value="2"/>
              <!--<el-option label="官网" value="3"/>-->
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="menuLevelQuery" size="small" id="el-select" style="vertical-align:top;">
              <el-option label="菜单级别" value=""/>
              <el-option label="一级" value="1"/>
              <el-option label="二级" value="2"/>
              <el-option label="三级" value="3"/>
              <el-option label="四级" value="4"/>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input v-model="menuNameQuery" placeholder="菜单名称"  size="small" id="inputheight" style="vertical-align:top;"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="supMenuNameQuery" placeholder="父菜单名称" size="small" id="inputheight" style="vertical-align:top;"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" v-on:click="search" size="small" style="line-height:14px;vertical-align:top;">查询</el-button>
          </el-form-item>
          <el-form-item class="button-align">
            <el-button type="primary" @click="handleAdd" size="small" v-if="getAuth(0)">新增菜单</el-button>
          </el-form-item>
          <el-form-item class="button-align">
            <el-button type="danger" @click="batchDelete" :disabled="this.sels.length===0" size="small" v-if="getAuth(3)">
              批量删除
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <!--列表-->
      <el-table :data="list" v-loading="listLoading" border
                style="width: 100%; font-size: 12px;" @selection-change="selsChange" row-class-name="tabRow">
        <el-table-column type="selection"></el-table-column>
        <el-table-column align="center" :formatter="formatAccountType" label="菜单类型"></el-table-column>
        <!--<el-table-column align="center" prop="supMenuID" label="上级菜单ID"></el-table-column>-->
        <el-table-column align="center" prop="supMenuName" label="上级菜单名称"></el-table-column>
        <!--<el-table-column align="center" :formatter="formatMenuLevel" label="菜单级别"></el-table-column>-->
        <!--<el-table-column align="center" prop="menuName" label="菜单名称"></el-table-column>-->
        <el-table-column align="center" prop="menuName" label="菜单名称">
          <template scope="scope">
            <div class="nub1" v-if="scope.row.menuLevel === 1">1</div>
            <div class="nub2" v-if="scope.row.menuLevel === 2">2</div>
            <div class="nub3" v-if="scope.row.menuLevel === 3">3</div>
            <div class="nub4" v-if="scope.row.menuLevel === 4">4</div>
            <div style="float: left;margin-left: 5px;">{{ scope.row.menuName }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="menuUrl" label="节点链接"></el-table-column>
        <el-table-column align="center" prop="menuTop" label="菜单顺序"></el-table-column>
        <el-table-column align="center" prop="icon" label="菜单图标">
          <template scope="scope">
            <i class="icon iconfont" v-html="scope.row.icon"></i>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="buttonControl" label="按钮标识">
          <template scope="scope">
            <i class="el-icon-edit" v-if="scope.row.buttonControl === '1'"></i>
          </template>
        </el-table-column>
        <el-table-column align="center" width="150" :formatter="createTimeStr" label="创建时间"></el-table-column>
        <el-table-column align="center" width="150" label="操作">
          <template scope="scope">
            <el-dropdown trigger="click">
              <el-button type="primary" size="small">
                更多操作<i class="el-icon-caret-bottom el-icon--right"></i>
              </el-button>
              <el-dropdown-menu scope="dropdown" style="text-align: center;color: #20a0ff;font-size: 12px;min-width: 80px;">
                <span @click="handleCopy(scope.$index, scope.row)" v-if="getAuth(5)">
                  <el-dropdown-item>复  制</el-dropdown-item>
                </span>
                <span @click="handleEdit(scope.$index, scope.row)" v-if="getAuth(1)">
                  <el-dropdown-item>编  辑</el-dropdown-item>
                </span>
                <span @click="handleDelete(scope.$index, scope.row)" v-if="getAuth(2)">
                  <el-dropdown-item>删  除</el-dropdown-item>
                </span>
                <span  @click="authSync(scope.row)" v-if="getAuth(4)">
                  <el-dropdown-item>权限同步</el-dropdown-item>
                </span>
                <span @click="handleChildren(scope.$index, scope.row)" v-if="getAuth(6) && scope.row.menuLevel !== 4">
                  <el-dropdown-item>子菜单排序</el-dropdown-item>
                </span>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
          <!--<template scope="scope">
            <el-button type="primary" @click="authSync(scope.row)" size="small" v-if="getAuth(4)">权限同步</el-button>
            <el-button type="warning" size="small" @click="handleEdit(scope.$index, scope.row)" v-if="getAuth(1)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="getAuth(2)">删除</el-button>
          </template>-->
        </el-table-column>
      </el-table>
      <el-col :span="24" class="toolbar" style="margin-top: 15px">
        <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]"
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;"
                       v-show="!listLoading">
        </el-pagination>
      </el-col>

      <!--新增/修改-->
      <el-dialog :title="dialogTitle" :visible.sync="showAdd" :close-on-click-modal="false" @close="clearInput" size="tiny">
        <el-form :model="menu" label-width="130px" :rules="menuFormRules" ref="menu" style="margin-top: -30px;">
          <el-form-item label="菜单类型" prop="accountType" id="formheight">
            <el-select style="width: 217px" v-model="menu.accountType" v-bind:class="{'borderStyle' : classControl}">
              <el-option label="请选择" value=""/>
              <el-option label="运营" value="0"/>
              <el-option label="商家" value="1"/>
              <el-option label="代理商" value="2"/>
              <!--<el-option label="官网" value="3"/>-->
            </el-select>
            <el-col v-bind:class="{'prompt' : classControl}" v-if="classControl">
              菜单类型与菜单级别均为必选
            </el-col>
          </el-form-item>
          <el-form-item label="菜单级别" prop="menuLevel" id="formheight">
            <el-select style="width: 217px" v-model="menu.menuLevel" v-bind:class="{'borderStyle' : classControl}">
              <el-option label="请选择" value=""/>
              <el-option label="一级" value="1"/>
              <el-option label="二级" value="2"/>
              <el-option label="三级" value="3"/>
              <el-option label="四级" value="4"/>
            </el-select>
          </el-form-item>
          <el-form-item label="菜单名称" prop="menuName" id="formheight">
            <el-input v-model="menu.menuName" style="width: 217px"></el-input>
          </el-form-item>
          <el-input v-model="menu.subMenuName" style="display: none"></el-input>
          <el-form-item label="上级菜单" prop="supMenuID" v-if="menu.menuLevel != 1" id="formheight">
            <el-select v-model="menu.supMenuID" style="width: 217px">
              <el-option v-for="(item,indxe) in supMenu" :label="item.menuName" :value="item.id"
                         :key="indxe"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="节点链接" prop="menuUrl" id="formheight">
            <el-input v-model="menu.menuUrl" style="width: 217px"></el-input>
          </el-form-item>
          <el-form-item label="菜单顺序" prop="menuTop" id="formheight">
            <el-input v-model="menu.menuTop" style="width: 217px"></el-input>
          </el-form-item>
          <el-form-item label="菜单图标" id="formheight">
            <el-select style="width: 217px;" v-model="menu.icon" clearable>
              <el-option v-for="(item, index) in iconList" :value="item.value" :key="index">
                <i class="icon iconfont" v-html="item.value"></i>
                <span style="margin-left:10px;">{{item.name}}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="按钮控制" id="menuControl">
            <el-switch v-model="menu.buttonControl" on-color="#13ce66" off-color="#ff4949" on-value="1" off-value="0"></el-switch>
          </el-form-item>
        </el-form>
        <div scope="footer" class="dialog-footer"
             style="text-align: right;">
          <el-button @click.native="clearInput">取消</el-button>
          <el-button type="primary" @click.native="handleSubmit">保存</el-button>
        </div>
      </el-dialog>
    </el-col>
    <el-col :span="24" style="padding-bottom: 0px;" v-show="authSyncShow">
      <el-dialog :title="dialogTitle2" v-model="showAdd2" size="tiny" :close-on-click-modal="false" @close="cancelSync" style="height: 600px;overflow-y: hidden">
      <el-form ref="authEntity" :model="authEntity" label-width="100px" :rules="authFormRules" v-loading="authLoading" element-loading-text="拼命同步中...">
        <el-form-item label="菜单ID" prop="authId">
          <el-input v-model="authEntity.authId" size="small" id="authId" disabled></el-input>
        </el-form-item>
        <el-form-item label="同步类型" prop="authType">
          <el-select v-model="authEntity.authType" disabled placeholder="请选择同步类型" size="small">
            <el-option label="运营" value="0"/>
            <el-option label="商家" value="1"/>
            <el-option label="代理商" value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item label="操作类型" prop="operateType">
          <el-select v-model="authEntity.operateType" placeholder="请选择操作类型" size="small">
            <el-option label="新增" value="add"></el-option>
            <el-option label="删除" value="delete"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="同步对象" prop="authObj">
          <el-checkbox-group v-model="authEntity.authObj">
            <el-checkbox  label="role" name="authObj">角色</el-checkbox >
            <el-checkbox  label="company" name="authObj">公司</el-checkbox >
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="同步备注" prop="authComment">
          <el-input type="textarea" id="authComment" v-model="authEntity.authComment" placeholder="请输入同步备注" size="small" resize="none" :rows="3" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="cancelSync">取消</el-button>
          <el-button id="authSyncBtn" type="primary" @click="doAuthSync">同步</el-button>
        </el-form-item>
      </el-form>
      </el-dialog>
    </el-col>
    <el-dialog title="子菜单排序" :visible.sync="dialogTableVisible" size="tiny" @close="hideMenuTop">
      <el-table :data="childMenuData" v-loading="listLoading" border style="width: 100%; font-size: 12px;" @selection-change="selsChange" row-class-name="tabRow">
        <el-table-column prop="menuName" label="菜单名称" align="center">
          <template scope="scope">
            {{ scope.row.menuName }}
          </template>
        </el-table-column>
        <el-table-column prop="menuTop" label="原菜单顺序" align="center">
          <template scope="scope">
            {{ scope.row.menuTop }}
          </template>
        </el-table-column>
        <el-table-column prop="menuTop" label="编辑菜单顺序" align="center">
          <template scope="scope">
            <el-input v-model="scope.row.newMenuTop" placeholder="菜单顺序" class="menuTopClass"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div scope="footer" class="dialog-footer">
        <el-button @click="hideMenuTop">取 消</el-button>
        <el-button type="primary" @click="saveMenuTop" :loading="saveMenuLoading">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getIcons} from '../../smartlight/common/js/icons.js'
  import {buttonAuth, resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default {
    data () {
      var validateConfirmSelect = (rule, value, callback) => {
        if (this.menu.menuLevel === '' || this.menu.accountType === '') {
          this.supMenu = []
          this.menu.supMenuID = ''
          this.classControl = true
        } else {
          this.classControl = false
          var para = Object.assign({})
          if (this.menu.menuLevel !== '1') {
            para.menuLevel = (Number(this.menu.menuLevel) - 1).toString()
            para.type = '0'
            para.accountType = this.menu.accountType
            if (this.oldAccountType !== this.menu.accountType || this.oldMenuLevel !== this.menu.menuLevel) {
              this.$http.post('/smartLight/web/baseMenu/getByManager.htm', para).then(response => {
                var resBody = response.body
                this.supMenu = resBody.result
                this.menu.supMenuID = ''
                this.oldAccountType = this.menu.accountType
                this.oldMenuLevel = this.menu.menuLevel
              })
            }
          } else {
            this.supMenu = []
            this.menu.supMenuID = ''
          }
          callback()
        }
      }
//      上级菜单验证
      var validateConfirmSubMenuID = (rule, value, callback) => {
        if (this.menu.supMenuID === '') {
          callback(new Error('请选择上级菜单'))
        } else {
          callback()
        }
      }
      // authId格式验证
      var authIdCheck = (rule, value, callback) => {
        if (!/^\d+$/.test(value)) {
          callback(new Error('菜单ID格式为数字且单个ID'))
        } else {
          callback()
        }
      }
      return {
        saveMenuLoading: false, // 保存菜单的动画按钮
        dialogTableVisible: false,
        childMenuData: [], // 子菜单
        list: [],
        total: 2,
        page: 1,
        pageSize: 10,
        showAdd: false,
        showAdd2: false,
        supMenu: [],
        dialogTitle: '',
        dialogTitle2: '权限同步',
        opType: 'add',
        accountQuery: '',
        menuLevelQuery: '',
        menuNameQuery: '',
        supMenuNameQuery: '',
        classControl: false,
        addLoading: false,
        sels: [], // 列表选中列
        accountTypeArr: {0: '运营', 1: '商家', 2: '代理商'},
        menuLevelArr: {1: '一级', 2: '二级', 3: '三级', 4: '四级'},
        menu: {
          accountType: '',
          menuLevel: '',
          menuName: '',
          supMenuID: '',
          supMenuName: '',
          menuUrl: '',
          menuTop: '',
          icon: '',
          buttonControl: '0'
        },
        oldAccountType: '',
        oldMenuLevel: '',
        listLoading: false,
        menuFormRules: {
          menuName: [
            {required: true, message: '请输入菜单名称', trigger: 'blur'}
          ],
          menuUrl: [
            {required: true, message: '请输入节点链接', trigger: 'blur'}
          ],
          menuTop: [
            {required: true, message: '请输入菜单顺序', trigger: 'blur'}
          ],
          supMenuID: [
            {required: true, validator: validateConfirmSubMenuID, trigger: 'change'}
          ],
          accountType: [
            {required: true, validator: validateConfirmSelect, trigger: 'change'}
          ],
          menuLevel: [
            {required: true, validator: validateConfirmSelect, trigger: 'change'}
          ]
        },
        authFormRules: {
          authId: [
            {required: true, trigger: 'blur', validator: authIdCheck}
          ],
          authType: [
            {required: true, message: '请选择同步类型', trigger: 'change'}
          ],
          operateType: [
            {required: true, message: '请选择操作类型', trigger: 'change'}
          ],
          authObj: [
            {type: 'array', required: true, message: '请选择同步对象', trigger: 'change'}
          ],
          authComment: [
            {required: false, message: '请输入备注', trigger: 'blur'}
          ]
        },
        iconList: [],
        listShow: true,
        authSyncShow: false,
        authEntity: {
          authId: '', // 菜单ID
          authType: '', // 同步类型
          operateType: '', // 操作类型
          authObj: [], // 同步对象
          authComment: '' // 同步备注
        },
        authLoading: false,
        adminButtons: [409, 410, 411, 412, 413, 508, 511] // 依次为新增、编辑、删除、批量删除、权限同步、复制、子菜单排序
      }
    },
    methods: {
      checkIfLogin () { // 判断是否登录超时
        var user = sessionStorage.getItem('user')
        if (!user) {
          this.$alert('登录超时，请重新登录！', ' ', {
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/login'})
            sessionStorage.clear()
          })
        } else {
          return true
        }
      },
      saveMenuTop () {
        for (var i in this.childMenuData) {
          if (this.childMenuData[i].newMenuTop === '') {
            this.$message({
              showClose: true,
              message: '菜单顺序不能为空',
              type: 'warning'
            })
            return
          } else {
            continue
          }
        }
        this.saveMenuLoading = true
        this.$http.post('/smartLight/web/baseMenu/updateChildMenuTop.htm', {list: this.childMenuData}).then(response => {
          this.saveMenuLoading = false
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.dialogTableVisible = false
            this.childMenuData = []
            this.loadMenuList()
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'warning'
            })
          }
        })
      },
//      changeSelectVal (val) {
//        this.menu.supMenuID = val
//        console.log(val)
//      },
//      分页查询
      loadMenuList () {
        this.listLoading = true
        var para = Object.assign({})
        para.pageNumber = this.page
        para.pageSize = this.pageSize
        para.accountType = this.accountQuery
        para.menuLevel = this.menuLevelQuery
        para.menuName = this.menuNameQuery
        para.supMenuName = this.supMenuNameQuery
        para.type = '0'
        this.$http.post('/smartLight/web/baseMenu/getList.htm', para).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.total = resBody.total
            this.list = resBody.result
            this.listLoading = false
          } else if (resBody.isSuccess === 2) {
            this.listLoading = false
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 【查询】
      search () {
        if (!this.checkIfLogin()) {
          return
        }
        this.page = 1
        this.loadMenuList()
      },
      clearInput () {
        this.showAdd = false
        this.menu = {
          accountType: '',
          menuLevel: '',
          menuName: '',
          supMenuID: '',
          supMenuName: '',
          menuUrl: '',
          menuTop: '',
          icon: '',
          buttonControl: '0'
        }
        this.oldAccountType = ''
        this.oldMenuLevel = ''
        this.$refs['menu'].resetFields()
      },
      clearInput2 () {
        this.showAdd2 = false
      },
//      删除
      handleDelete (index, row) {
        var ids = []
        ids.push(row.id)
        this.deleteMenu(ids)
      },
//      批量删除
      batchDelete () {
        if (!this.checkIfLogin()) {
          return
        }
        var ids = []
        this.sels.map(item => {
          ids.push(item.id)
        })
        this.deleteMenu(ids)
      },
//      执行删除
      deleteMenu (ids) {
        if (!this.checkIfLogin()) {
          return
        }
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.$http.post('/smartLight/web/baseMenu/deleteById.htm', ids).then(response => {
            var resBody = response.body
            if (resBody.isSuccess === 0) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.loadMenuList()
            } else if (resBody.isSuccess === 2) {
              sessionOut(this) // session超时处理
            } else {
              this.$message({
                showClose: true,
                message: '操作失败',
                type: 'error'
              })
            }
          })
        }).catch(() => {})
      },
      // 格式化按钮状态
      formatButton (val) {
        var flag = false
        if (val === '1') {
          flag = true
        }
        return flag
      },
//      选择需要删除的行
      selsChange: function (sels) {
        this.sels = sels
      },
//      分页
      handleSizeChange (val) {
        this.pageSize = val
        this.loadMenuList()
      },
      handleCurrentChange (val) {
        this.page = val
        this.loadMenuList()
      },
//      时间格式化
      createTimeStr (row, column) {
        var d = new Date(row.createTime)
        var year = d.getFullYear()
        var month = d.getMonth() + 1
        var date = d.getDate()
        var hour = d.getHours()
        var minute = d.getMinutes()
        var second = d.getSeconds()
        return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
      },
//      权限类型转中文
      formatAccountType (row, column) {
        return this.accountTypeArr[row.accountType]
      },
//      菜单级别转中文
      formatMenuLevel (row, column) {
        return this.menuLevelArr[row.menuLevel]
      },
//      添加初始化
      handleAdd () {
        this.classControl = false
        this.showAdd = true
        this.dialogTitle = '新增菜单'
      },
      // 复制该菜单
      handleCopy (index, row) {
        this.classControl = false
        this.showAdd = true
        this.dialogTitle = '编辑菜单'
        this.menu = {
          accountType: row.accountType.toString(),
          menuLevel: row.menuLevel.toString(),
          menuName: '',
          supMenuID: row.supMenuID,
          supMenuName: row.supMenuName,
          menuUrl: row.menuUrl,
          menuTop: row.menuTop.toString(),
          icon: row.icon,
          buttonControl: row.buttonControl
        }
        this.oldAccountType = row.accountType.toString()
        this.oldMenuLevel = row.menuLevel.toString()
        var para = Object.assign({})
        if (this.menu.menuLevel !== '1') {
          para.accountType = this.menu.accountType
          para.menuLevel = (Number(this.menu.menuLevel) - 1).toString()
          para.type = '0'
          this.$http.post('/smartLight/web/baseMenu/getByManager.htm', para).then(response => {
            var resBody = response.body
            this.supMenu = resBody.result
            this.oldAccountType = this.menu.accountType
            this.oldMenuLevel = this.menu.menuLevel
          })
        } else {
          this.supMenu = []
          this.menu.supMenuID = ''
        }
      },
      // 隐藏子菜单列表
      hideMenuTop () {
        this.dialogTableVisible = false
        this.childMenuData = []
      },
      // 子菜单排序
      handleChildren (index, row) {
        this.dialogTableVisible = true // 显示子菜单列表
        // 获取该菜单的所有子菜单
        var para = {
          type: '0',
          id: row.id
        }
        this.$http.post('/smartLight/web/baseMenu/getChildMenu.htm', para).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            var list = resBody.result
            for (var i in list) {
              var param = {id: list[i].id, menuName: list[i].menuName, menuTop: list[i].menuTop, newMenuTop: ''}
              this.childMenuData.push(param)
            }
          } else if (resBody.isSuccess === 2) {  // 超时
            sessionOut(this) // session超时处理
          } else {  // 其他情况
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
//      修改初始化
      handleEdit (index, row) {
        this.classControl = false
        this.showAdd = true
        this.dialogTitle = '编辑菜单'
        this.menu = {
          accountType: row.accountType.toString(),
          menuLevel: row.menuLevel.toString(),
          menuName: row.menuName,
          id: row.id,
          supMenuID: row.supMenuID,
          supMenuName: row.supMenuName,
          menuUrl: row.menuUrl,
          menuTop: row.menuTop.toString(),
          icon: row.icon,
          buttonControl: row.buttonControl
        }
        this.oldAccountType = row.accountType.toString()
        this.oldMenuLevel = row.menuLevel.toString()
        var para = Object.assign({})
        if (this.menu.menuLevel !== '1') {
          para.accountType = this.menu.accountType
          para.menuLevel = (Number(this.menu.menuLevel) - 1).toString()
          para.type = '0'
          this.$http.post('/smartLight/web/baseMenu/getByManager.htm', para).then(response => {
            var resBody = response.body
            this.supMenu = resBody.result
            this.oldAccountType = this.menu.accountType
            this.oldMenuLevel = this.menu.menuLevel
          })
        } else {
          this.supMenu = []
          this.menu.supMenuID = ''
        }
      },
//      执行新增或删除 复制该菜单为新增新菜单
      handleSubmit () {
        if (!this.checkIfLogin()) {
          return
        }
        this.$refs.menu.validate((valid) => {
          if (this.menu.menuLevel === '' || this.menu.accountType === '') {
            valid = false
            this.classControl = true
          }
          if (valid) {
            for (var n = 0; n < this.supMenu.length; n++) {
              if (this.menu.supMenuID === this.supMenu[n].id) {
                this.menu.supMenuName = this.supMenu[n].menuName
              }
            }
            var url = '/smartLight/web/baseMenu/save.htm'
            this.addLoading = true
            this.$http.post(url, this.menu).then(response => {
              var resBody = response.body
              if (resBody.isSuccess === 0) {
                this.showAdd = false
                this.addLoading = false
                this.$message({
                  showClose: true,
                  message: '操作成功',
                  type: 'success'
                })
                this.loadMenuList()
              } else {
                this.$message({
                  showClose: true,
                  message: resBody.errorMsg,
                  type: 'error'
                })
              }
            })
          }
        })
      },
      // 转向权限同步界面
      authSync (row) {
        this.authSyncShow = true
        // 表单初始化
        this.authEntity.authId = ''
        this.authEntity.authType = row.accountType + ''
        this.authEntity.operateType = 'add'
        this.authEntity.authObj = ['role', 'company']
        this.authEntity.authComment = ''
        this.authEntity.authId = row.id
        this.showAdd2 = true
      },
      // 取消权限同步操作
      cancelSync () {
        this.authSyncShow = false
        this.showAdd2 = false
      },
      // 提交权限同步
      doAuthSync () {
        this.$refs.authEntity.validate((valid) => {
          if (valid) {
            this.authLoading = true
            let para = {
              type: 0,
              authEntity: this.authEntity
            }
            this.$http.post('/smartLight/web/baseMenu/doAuthSync.htm', para).then(response => {
              var resBody = response.body
              let isSuccess = resBody.isSuccess
              this.showAdd2 = false
              this.authLoading = false
              if (isSuccess === 0) {  // 成功
                this.$alert(resBody.errorMsg, {
                  type: 'success'
                }).then(() => {
                  this.cancelSync()
                })
              } else if (isSuccess === 2) {  // 超时
                sessionOut(this) // session超时处理
              } else {  // 其他情况
                this.$message({
                  showClose: true,
                  message: resBody.errorMsg,
                  type: 'error'
                })
              }
            })
          } else {
//            window.location.reload()
            return false
          }
        })
      },
      // 获取页面按钮权限权限
      getAuth (index) {
        return buttonAuth(index, 0, this.adminButtons, [], [])
      }
    },
    mounted () {
      // 浏览器向前或向后处理
      resetBreads(this)
      this.loadMenuList()
      this.iconList = getIcons()
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .button-align
    float: right;
    margin 5px !important;

  .tabRow
    font-size: 12px;

  .el-dialog--small
    width: 420px !important;

  .prompt
    color: #ff4949;
    font-size: 12px;
    left: 0;
    line-height: 1;
    padding-top: 4px;
    position: absolute;
    top: 100%;

  #formheight
    margin: 14px 0;
    height: 38px;
    .el-form-item__content
      height: 30px;
    .el-input
      height: 30px;
      .el-input__inner
        height: 30px;

  .borderStyle
    .el-input .el-input__inner {
      border-color: #ff4949 !important;
    }

  #pagination
    background-color: transparent
    .el-input__inner
      width: 120px

  .el-table__body-wrapper
    overflow-x: hidden

  #inputheight
    .el-input__inner
      height: 30px
  #el-select
    .el-input
      vertical-align:top;
  #authId
    width 215px;
  #authComment
    width 350px;
  #authSyncBtn
    margin-left 30px;
  .nub1
    background-color:#20A0FF;width:16px;height:16px;color:#fff;line-height:16px;text-align:center;border-radius:2px;font-size:12px;
    float: left;margin-left:10px;margin-top:4px;
  .nub2
    background-color:#F7BA2A;width:16px;height:16px;color:#fff;line-height:16px;text-align:center;border-radius:2px;font-size:12px;
    float: left;margin-left:10px;margin-top:4px;
  .nub3
    background-color:#13CE66;width:16px;height:16px;color:#fff;line-height:16px;text-align:center;border-radius:2px;font-size:12px;
    float: left;margin-left:10px;margin-top:4px;
  .nub4
    background-color:#FF4949;width:16px;height:16px;color:#fff;line-height:16px;text-align:center;border-radius:2px;font-size:12px;
    float: left;margin-left:10px;margin-top:4px;
  .menuTopClass
    border: none;
    .el-input__inner
     text-align :center;
</style>
